﻿using System;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;

namespace Be {

    /// <summary>
    /// The class represents a booking
    /// </summary>
    [DataContract]
    public class BeBooking {

        /// <summary>
        /// Constructs an object with the different properties.
        /// Used for get bookings
        /// </summary>
        /// <param name="id">The id of the booking</param>
        /// <param name="startTime">The starttime of the booking</param>
        /// <param name="endTime">The endtime of the booking</param>
        /// <param name="startLatitude">The start latitude of the booking</param>
        /// <param name="startLongitude">The start longitude of the booking</param>
        /// <param name="endLatitude">The end latitude of the booking</param>
        /// <param name="endLongitude">The end longitude of the booking</param>
        /// <param name="userId">The id of the user</param>
        /// <param name="lessonId">The id of the lesson</param>
        public BeBooking(int id, DateTime startTime, DateTime endTime, double startLatitude, double startLongitude, double endLatitude, double endLongitude, string userId, int lessonId) {
            Id = id;
            StartTime = startTime;
            EndTime = endTime;
            StartLatitude = startLatitude;
            StartLongitude = startLongitude;
            EndLatitude = endLatitude;
            EndLongitude = endLongitude;
            UserId = userId;
            LessonId = lessonId;
        }

        /// <summary>
        /// Constructs an object with the different properties.
        /// Used for saving bookings
        /// </summary>
        /// <param name="startTime">The starttime of the booking</param>
        /// <param name="endTime">The endtime of the booking</param>
        /// <param name="startLatitude">The start latitude of the booking</param>
        /// <param name="startLongitude">The start longitude of the booking</param>
        /// <param name="endLatitude">The end latitude of the booking</param>
        /// <param name="endLongitude">The end longitude of the booking</param>
        /// <param name="userId">The id of the user</param>
        /// <param name="teacherId">The id of the teacher</param>
        /// <param name="lessonId">The id of the lesson</param>
        public BeBooking(DateTime startTime, DateTime endTime, double startLatitude, double startLongitude, double endLatitude, double endLongitude, string userId, string teacherId, int lessonId) {
            StartTime = startTime;
            EndTime = endTime;
            StartLatitude = startLatitude;
            StartLongitude = startLongitude;
            EndLatitude = endLatitude;
            EndLongitude = endLongitude;
            UserId = userId;
            TeacherId = teacherId;
            LessonId = lessonId;
        }

        /// <summary>
        /// Constructs an object with the different properties.
        /// Used for saving bookings
        /// </summary>
        /// <param name="id">The id of the booking</param>
        /// <param name="startTime">The starttime of the booking</param>
        /// <param name="endTime">The endtime of the booking</param>
        /// <param name="startLatitude">The start latitude of the booking</param>
        /// <param name="startLongitude">The start longitude of the booking</param>
        /// <param name="endLatitude">The end latitude of the booking</param>
        /// <param name="endLongitude">The end longitude of the booking</param>
        /// <param name="userId">The id of the user</param>
        /// <param name="teacherId">The id of the teacher</param>
        /// <param name="lessonId">The id of the lesson</param>
        public BeBooking(int id, DateTime startTime, DateTime endTime, double startLatitude, double startLongitude, double endLatitude, double endLongitude, string userId, string teacherId, int lessonId) {
            Id = id;
            StartTime = startTime;
            EndTime = endTime;
            StartLatitude = startLatitude;
            StartLongitude = startLongitude;
            EndLatitude = endLatitude;
            EndLongitude = endLongitude;
            UserId = userId;
            TeacherId = teacherId;
            LessonId = lessonId;
        }

        /// <summary>
        /// Constructs an object with the different properties.
        /// </summary>
        /// <param name="id">The id of the booking</param>
        /// <param name="starttime">The starttime of the booking</param>
        /// <param name="endtime">The endtime of the booking</param>
        /// <param name="userId">The id of the user</param>
        /// <param name="type">The type of the lesson</param>
        public BeBooking(int id, DateTime starttime, DateTime endtime, string userId, string type) {
            Id = id;
            StartTime = starttime;
            EndTime = endtime;
            UserId = userId;
            LessonType = type;
        }

        /// <summary>
        /// Constructs the object with an id.
        /// Used for delete bookings
        /// </summary>
        /// <param name="id">The id of the booking</param>
        public BeBooking(int id) {
            Id = id;
        }

        /// <summary>
        /// Constructs an object with the different properties
        /// </summary>
        /// <param name="startTime">The starttime of the booking</param>
        /// <param name="endTime">The endtime of the booking</param>
        /// <param name="teacherId">The id of the teacher</param>
        public BeBooking(DateTime startTime, DateTime endTime, string teacherId) {
            StartTime = startTime;
            EndTime = endTime;
            TeacherId = teacherId;
        }

        /// <summary>
        /// The id of the booking
        /// </summary>
        [DataMember]
        public int Id { get; private set; }

        /// <summary>
        /// The starttime of the booking
        /// </summary>
        [DataMember]
        [Required]
        [RegularExpression(@"^\d{2}-\d{2}-\d{4} \d{2}:\d{2}$")]
        public DateTime StartTime { get; set; }

        /// <summary>
        /// The endtime of the booking
        /// </summary>
        [DataMember]
        [Required]
        [RegularExpression(@"^\d{2}-\d{2}-\d{4} \d{2}:\d{2}$")]
        public DateTime EndTime { get; set; }

        /// <summary>
        /// The start latitude of the booking
        /// </summary>
        [DataMember]
        [Required]
        [RegularExpression(@"^\d{2},\d{8}$")]
        public double StartLatitude { get; set; }

        /// <summary>
        /// The start longitude of the booking
        /// </summary>
        [DataMember]
        [Required]
        [RegularExpression(@"^\d{2},\d{8}$")]
        public double StartLongitude { get; set; }

        /// <summary>
        /// The end latitude of the booking
        /// </summary>
        [DataMember]
        [Required]
        [RegularExpression(@"^\d{2},\d{8}$")]
        public double EndLatitude { get; set; }

        /// <summary>
        /// The end longitude of the booking
        /// </summary>
        [DataMember]
        [Required]
        [RegularExpression(@"^\d{2},\d{8}$")]
        public double EndLongitude { get; set; }

        /// <summary>
        /// The id of the user
        /// </summary>
        [DataMember]
        [Required(AllowEmptyStrings = false)]
        public string UserId { get; private set; }

        /// <summary>
        /// The id of the lessons
        /// </summary>
        [DataMember]
        [Required]
        public int LessonId { get; set; }

        /// <summary>
        /// The id of the teacher
        /// </summary>
        [DataMember]
        [Required(AllowEmptyStrings = false)]
        public string TeacherId { get; set; }

        /// <summary>
        /// The type of the lesson
        /// </summary>
        [DataMember]
        [Required(AllowEmptyStrings = false)]
        public string LessonType { get; set; }

        /// <summary>
        /// Check if two bookings are equal
        /// </summary>
        /// <param name="obj">The booking to check</param>
        /// <returns>True if the two bookings are equal. False otherwise</returns>
        public override bool Equals(object obj) {
            BeBooking booking = obj as BeBooking;
            if(booking == null) return false;
            return Id.Equals(booking.Id);
        }

        /// <summary>
        /// Get the hashcode from the booking
        /// </summary>
        /// <returns>The hashcode</returns>
        public override int GetHashCode() {
            return Id.GetHashCode();
        }
    }
}